/*
 * @lc app=leetcode.cn id=504 lang=csharp
 *
 * [504] 七进制数
 */

// @lc code=start
public class Solution {
    public string ConvertToBase7(int num) {
        if (num == 0)
        {
            return "0";
        }
        bool isNegative = num < 0;
        num = Math.Abs(num);
        StringBuilder sb = new StringBuilder();
        while (num > 0)
        {
            sb.Append(num % 7);
            num /= 7;
        }
        if (isNegative)
        {
            sb.Append("-");
        }
        char[] charArray = sb.ToString().ToCharArray();
        Array.Reverse(charArray);
        return new string(charArray);
    
    }
}
// @lc code=end

